package com.mask.roll.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mask.roll.common.code.ServiceEnums;
import com.mask.roll.common.constant.RollConstants;
import com.mask.roll.common.util.RollResponse;
import com.mask.roll.edu.entity.Course;
import com.mask.roll.edu.entity.Teacher;
import com.mask.roll.edu.service.CourseService;
import com.mask.roll.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author hx
 * @since 2021/10/26 4:58 下午
 */

@RestController
@RequestMapping("/edu/front")
@Api(tags = "前台课程管理")
public class IndexFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    //查询8条热门课程，查询前4条名师
    @GetMapping("/get/index")
    @ApiOperation("获取首页课程名师")
    public RollResponse index(){
        QueryWrapper<Course> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("gmt_create");
        courseWrapper.last("limit 8");
        List<Course> courseList = courseService.list(courseWrapper);

        QueryWrapper<Teacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("gmt_create");
        teacherWrapper.last("limit 4");
        List<Teacher> teacherList = teacherService.list(teacherWrapper);

        HashMap<Object, Object> map = new HashMap<>();
        map.put("courseList",courseList);
        map.put("teacherList",teacherList);

        return RollResponse.result(ServiceEnums.COURSE_FRONT_GET_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.COURSE_FRONT_GET_SUCCESS.getMessage(),map);
    }
}
